using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using PaxScript.Net;

namespace stateHepek
{
    public partial class ScriptEditor : Form
    {
        private int prethodno;
        Form1 roditelj;

        public ScriptEditor(Form1 r)
        {
            InitializeComponent();
            roditelj = r;
            prethodno = 1;
        }

        private void izaddjiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ScriptEditor_Load(object sender, EventArgs e)
        {
            richTextBox1.Text = Form1.scriptCode;
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Lines.Length != prethodno)
            {
                brojevi.Text = "0";
                for (int i = 1; i < richTextBox1.Lines.Length; i++)
                    brojevi.Text = brojevi.Text + Environment.NewLine + i;
                brojevi.SelectionLength = 0;

                brojevi.SelectionStart = brojevi.Text.Length;

                brojevi.ScrollToCaret();
            }

        }

        private void novaScriptaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            brojevi.Text = "0";
        }

        private void ucitajScriptuToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void otvoriScriptuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "Otvori Simulacijsku Scriptu";
            fdlg.Filter = "Simulacijska Scripta (*.ss)|*.ss|All Files (*.*)|*.*";
            fdlg.FilterIndex = 1;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                StreamReader streamRead = new StreamReader(fdlg.FileName);
                Form1.scriptCode = streamRead.ReadToEnd();
                richTextBox1.Text = Form1.scriptCode;
            }
        }

        private void spasiScriptuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog spasiDialog = new SaveFileDialog();
            spasiDialog.Title = "Spasi Skriptu";
            spasiDialog.Filter = "Simulacijska Scripta (*.ss)|*.ss|All Files (*.*)|*.*";
            spasiDialog.FilterIndex = 1;
            spasiDialog.RestoreDirectory = true;

            if (spasiDialog.ShowDialog() == DialogResult.OK)
                richTextBox1.SaveFile(spasiDialog.FileName, RichTextBoxStreamType.PlainText);
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripDropDownButton1_Click(object sender, EventArgs e)
        {
            Form1.scriptCode = richTextBox1.Text;
            roditelj.play_Click(this, null);

            this.Close();
        }
    }
}